package com.delivery.controller.user;

import com.delivery.dto.OrderPaymentDTO;
import com.delivery.dto.PlaceOrderDTO;
import com.delivery.result.Result;
import com.delivery.service.OrderService;
import com.delivery.vo.OrderPaymentVO;
import com.delivery.vo.PlaceOrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order")
@Api("订单相关接口")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 提交订单
     * @return
     */
    @PostMapping("/submit")
    public Result<PlaceOrderVO> placeOrder(@RequestBody PlaceOrderDTO dto){

        log.info("用户下单：{}", dto);
        PlaceOrderVO placeOrderVO = orderService.placeOrder(dto);
        return Result.success(placeOrderVO);
    }

    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrderPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
}
